import mxgraph from 'pages/mxgraph/graph/index';
const { mxConstants, mxImage } = mxgraph;
class CanvasUtil {
  constructor(){
    this.vertexImg = {};
    this.vertexImg.mainHandle = this.createSvgImage(
      18,
      18,
      '<rect x="9" y="9" width="9" height="9" stroke="#fff" fill="' +
      '#000' +
      '" stroke-width="1"/>'
    ),
    this.vertexImg.secondaryHandle = this.createSvgImage(
      16,
      16,
      '<path d="m 8 3 L 13 8 L 8 13 L 3 8 z" stroke="#fff" fill="#fca000"/>'
    );
    this.vertexImg.fixedHandle = this.createSvgImage(
      18,
      18,
      '<circle cx="9" cy="9" r="5" stroke="#fff" fill="' +
      '#000' +
      '" stroke-width="1"/><path d="m 7 7 L 11 11 M 7 11 L 11 7" stroke="#fff"/>'
    );
    this.vertexImg.terminalHandle = this.createSvgImage(
      18,
      18,
      '<circle cx="9" cy="9" r="5" stroke="#fff" fill="' +
     '#000' +
      '" stroke-width="1"/><circle cx="9" cy="9" r="2" stroke="#fff" fill="transparent"/>'
    );
  }

  createHint() {
    let hint = document.createElement("div");
    hint.className = "geHint";
    hint.style.whiteSpace = "nowrap";
    hint.style.position = "absolute";
	
    return hint;
  }
	
	 formatHintText(pixels, unit) {
    switch (unit) {
      case mxConstants.POINTS:
        return pixels;
      case mxConstants.MILLIMETERS:
        return (pixels / mxConstants.PIXELS_PER_MM).toFixed(1);
      case mxConstants.INCHES:
        return (pixels / mxConstants.PIXELS_PER_INCH).toFixed(2);
    }
  }
  createSvgImage (w, h, data) {
    let tmp = unescape(
      encodeURIComponent(
        '<!DOCTYPE svg PUBLIC "-////W3C////DTD SVG 1.1////EN" "http:////www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">' +
        '<svg xmlns="http:////www.w3.org/2000/svg" xmlns:xlink="http:////www.w3.org/1999/xlink" width="' +
        w +
        'px" height="' +
        h +
        'px" ' +
        'version="1.1">' +
        data +
        "</svg>"
      )
    );
  
    return new mxImage(
      "data:image/svg+xml;base64," +
      (window.btoa ? btoa(tmp) : window.Base64.encode(tmp, true)),
      w,
      h
    );
  }

}
export default  new CanvasUtil();